package com.sunwayhorizo.health.hl7.rim;

import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.SAADMINISTRATIONUNITCDSETCODE;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.SAROUTECDSETCODE;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.jboss.seam.annotations.Name;

import com.sunwayhorizo.health.common.DataTypeUtil;
import com.sunwayhorizo.health.common.StrUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.IVL_PQ;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.SET_RTO_PQ;
import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;


@NamedQueries(value = {             
            @NamedQuery(name = "SubstanceAdministration.findAll", query = "select o from SubstanceAdministration o")
            } )
@Name("SubstanceAdministration")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue ("SBADM")
public class SubstanceAdministration extends Procedure implements Serializable {
	private static final long serialVersionUID = 1L;
/*
 * public CE administrationUnitCode;
    public SET_RTO_PQ doseCheckQuantity;
    public IVL_PQ doseQuantity;
    public SET_RTO_PQ maxDoseQuantity;
    public IVL_PQ rateQuantity;
    public CE routeCode;
*/    
    public SubstanceAdministration() throws Hl7Exception{
    }
    
    public SubstanceAdministration(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }

    public void setAdministrationUnitCode(CE ce) 
    {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            this.setRimCoreActCdSets(ce, SAADMINISTRATIONUNITCDSETCODE);
        }
        else
        {
            this.setSaAdministrationUnitCodeEtsId(ce.code().toString());
        }
    }

    public CE getAdministrationUnitCode() throws Hl7Exception
    {
    	if (this.getSaAdministrationUnitCodeEtsId().equals(SAADMINISTRATIONUNITCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getSaAdministrationUnitCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getSaAdministrationUnitCodeEtsId()); 
        return null;    
    }
/*
    public void setDoseCheckQuantity(SET_RTO_PQ doseCheckQuantity) {
        this.doseCheckQuantity = doseCheckQuantity;
    }

    public SET_RTO_PQ getDoseCheckQuantity() {
        return null;
    }
*/
    public void setDoseQuantity(IVL_PQ doseQuantity) {
        this.setSaDoseLowValueTxt( (doseQuantity.low() != null && doseQuantity.low().value() != null ? doseQuantity.low().value().toString() : ""));
        this.setSaDoseLowValueUomCode((doseQuantity.low().unit().toString().equals("<Null:NullFlavor: NI>") ? "" : doseQuantity.low().unit().toString()));
        this.setSaDoseLowInclusiveFlag(doseQuantity.lowClosed().literal().toString());
        
        this.setSaDoseHighValueTxt((doseQuantity.high() != null && doseQuantity.high().value() != null ? doseQuantity.high().value().toString() : ""));
        this.setSaDoseHighValueUomCode((doseQuantity.high().unit().toString().equals("<Null:NullFlavor: NI>") ? "" : doseQuantity.high().unit().toString()));
        this.setSaDoseHighInclusiveFlag(doseQuantity.highClosed().literal().toString());
        
        this.setSaDoseIvlValueTxt((doseQuantity.width() != null && doseQuantity.width().value() != null ? doseQuantity.width().value().toString() : ""));
        this.setSaDoseIvlValueUomCode((doseQuantity.width() != null && doseQuantity.width().unit() != null ? doseQuantity.width().unit().toString() : ""));
    }

    public IVL_PQ getDoseQuantity() throws Hl7Exception {
        return  DataTypeUtil.getIVL_PQ((this.getSaDoseLowValueTxt() == null ? "" : this.getSaDoseLowValueTxt()), (this.getSaDoseLowValueUomCode() == null ? "" : this.getSaDoseLowValueUomCode()));
    }

   
    public void setRateQuantity(IVL_PQ rateQuantity) {
        this.setSaRateLowValueTxt( rateQuantity.low().value().toString());
        this.setSaRateLowValueUomCode(rateQuantity.low().unit().toString());
        this.setSaRateLowInclusiveFlag(rateQuantity.lowClosed().literal().toString());
        
        this.setSaRateHighValueTxt(rateQuantity.high().value().toString());
        this.setSaRateHighValueUomCode(rateQuantity.high().unit().toString());
        this.setSaRateHighInclusiveFlag(rateQuantity.highClosed().literal().toString());
        
        this.setSaRateIvlValueTxt(rateQuantity.width().value().toString());
        this.setSaRateIvlValueUomCode(rateQuantity.width().unit().toString());
    }

    public IVL_PQ getRateQuantity() throws Hl7Exception {
       
        return  DataTypeUtil.getIVL_PQ(this.getSaRateLowValueTxt(), this.getSaRateLowValueUomCode());
    }
    
    /**
     * 设置最大剂量
     * @param aaMaxdoseValue IVL_PQ类型的最大剂量值
     */
    public  void setSaMaxdoseValue(PQ saMaxdoseValue)
    {
        this.setSaMaxdoseValueTxt((saMaxdoseValue.value().literal().toString().equals("<Null:NullFlavor: NI>") ? "" : saMaxdoseValue.value().literal().toString()));
        this.setSaMaxdoseValueUomCode((saMaxdoseValue.unit().code().toString().equals("<Null:NullFlavor: NI>") ? "" : saMaxdoseValue.unit().code().toString()));
    }
    
    /**
     * 得到最大剂量/单位
     * @return PQ
     * @throws Hl7Exception
     */
    public PQ getSaMaxdoseValue() throws Hl7Exception
    {
        return DataTypeUtil.getPQ((StrUtil.isNotEmpty(this.getSaMaxdoseValueTxt()) ? this.getSaMaxdoseValueTxt() : ""), (StrUtil.isNotEmpty(this.getSaMaxdoseValueUomCode()) ? this.getSaMaxdoseValueUomCode() : "" ));
    }
    
    /**
     * 设置最多天数/单位
     * @param saMaxdaysValue PQ类型的最多天数/单位
     */
    public  void setSaMaxdaysValue(PQ saMaxdaysValue)
    {
        this.setSaMaxdaysValueTxt((saMaxdaysValue.value().literal().toString().equals("<Null:NullFlavor: NI>") ? "" : saMaxdaysValue.value().literal().toString()));
        this.setSaMaxdaysValueUomCode((saMaxdaysValue.unit().code().toString().equals("<Null:NullFlavor: NI>") ? "" : saMaxdaysValue.unit().code().toString()));
    }
    
    /**
     * 得到最多天数/单位
     * @return PQ
     * @throws Hl7Exception
     */
    public PQ getSaMaxdaysValue() throws Hl7Exception
    {
        return DataTypeUtil.getPQ((StrUtil.isNotEmpty(this.getSaMaxdaysValueTxt()) ? this.getSaMaxdaysValueTxt() : ""), (StrUtil.isNotEmpty(this.getSaMaxdaysValueUomCode()) ? this.getSaMaxdaysValueUomCode() : "" ));
    }

    /**
     * 设置用药途径
     * @param ce
     */
    public void setRouteCode(CE ce) 
    {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            this.setRimCoreActCdSets(ce, SAROUTECDSETCODE);
        }
        else
        {
            this.setSaRouteCodeEtsId(ce.code().toString());
        }
    }
    
    /**
     * 得到用药途径
     * @return
     * @throws Hl7Exception
     */
    public CE getRouteCode() throws Hl7Exception
    {
    	if (this.getSaRouteCodeEtsId().equals(SAROUTECDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getSaRouteCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getSaRouteCodeEtsId()); 
        return null;    
     }
    
//SubstanceAdministration
        @Column(name = "SA_DOSE_HIGH_INCLUSIVE_FLAG")    private String saDoseHighInclusiveFlag;
        @Column(name = "SA_DOSE_HIGH_VALUE_TXT")    private String saDoseHighValueTxt;
        @Column(name = "SA_DOSE_HIGH_VALUE_UOM_CODE")    private String saDoseHighValueUomCode;
        @Column(name = "SA_DOSE_IVL_VALUE_TXT")    private String saDoseIvlValueTxt;
        @Column(name = "SA_DOSE_IVL_VALUE_UOM_CODE")    private String saDoseIvlValueUomCode;
        @Column(name = "SA_DOSE_LOW_INCLUSIVE_FLAG")    private String saDoseLowInclusiveFlag;
        @Column(name = "SA_DOSE_LOW_VALUE_TXT")    private String saDoseLowValueTxt;
        @Column(name = "SA_DOSE_LOW_VALUE_UOM_CODE")    private String saDoseLowValueUomCode;
        @Column(name = "SA_RATE_HIGH_INCLUSIVE_FLAG")    private String saRateHighInclusiveFlag;
        @Column(name = "SA_RATE_HIGH_VALUE_TXT")    private String saRateHighValueTxt;
        @Column(name = "SA_RATE_HIGH_VALUE_UOM_CODE")    private String saRateHighValueUomCode;
        @Column(name = "SA_RATE_IVL_VALUE_TXT")    private String saRateIvlValueTxt;
        @Column(name = "SA_RATE_IVL_VALUE_UOM_CODE")    private String saRateIvlValueUomCode;
        @Column(name = "SA_RATE_LOW_INCLUSIVE_FLAG")    private String saRateLowInclusiveFlag;
        @Column(name = "SA_RATE_LOW_VALUE_TXT")    private String saRateLowValueTxt;
        @Column(name = "SA_RATE_LOW_VALUE_UOM_CODE")    private String saRateLowValueUomCode;
        @Column(name = "SA_ROUTE_CODE_ETS_ID")    
        private String saRouteCodeEtsId = SAROUTECDSETCODE.toString();
        @Column(name = "SA_ADM_UNIT_CODE_ETS_ID")    
        private String saAdministrationUnitCodeEtsId = SAADMINISTRATIONUNITCDSETCODE.toString();
        
        @Column(name = "SA_MAXDOSE_VALUE_TXT")    private String saMaxdoseValueTxt;
        @Column(name = "SA_MAXDOSE_VALUE_UOM_CODE")    private String saMaxdoseValueUomCode;
        @Column(name = "SA_MAXDAYS_VALUE_TXT")    private String saMaxdaysValueTxt;
        @Column(name = "SA_MAXDAYS_VALUE_UOM_CODE")    private String saMaxdaysValueUomCode;
        
     private String getSaAdministrationUnitCodeEtsId() {
			return saAdministrationUnitCodeEtsId;
		}

		private void setSaAdministrationUnitCodeEtsId(
				String saAdministrationUnitCodeEtsId) {
			this.saAdministrationUnitCodeEtsId = saAdministrationUnitCodeEtsId;
		}

	private String getSaDoseHighInclusiveFlag() {
         return saDoseHighInclusiveFlag;
     }

     private void setSaDoseHighInclusiveFlag(String saDoseHighInclusiveFlag) {
         this.saDoseHighInclusiveFlag = saDoseHighInclusiveFlag;
     }

     private String getSaDoseHighValueTxt() {
         return saDoseHighValueTxt;
     }

     private void setSaDoseHighValueTxt(String saDoseHighValueTxt) {
         this.saDoseHighValueTxt = saDoseHighValueTxt;
     }

     private String getSaDoseHighValueUomCode() {
         return saDoseHighValueUomCode;
     }

     private void setSaDoseHighValueUomCode(String saDoseHighValueUomCode) {
         this.saDoseHighValueUomCode = saDoseHighValueUomCode;
     }

     private String getSaDoseIvlValueTxt() {
         return saDoseIvlValueTxt;
     }

     private void setSaDoseIvlValueTxt(String saDoseIvlValueTxt) {
         this.saDoseIvlValueTxt = saDoseIvlValueTxt;
     }

     private String getSaDoseIvlValueUomCode() {
         return saDoseIvlValueUomCode;
     }

     private void setSaDoseIvlValueUomCode(String saDoseIvlValueUomCode) {
         this.saDoseIvlValueUomCode = saDoseIvlValueUomCode;
     }

     private String getSaDoseLowInclusiveFlag() {
         return saDoseLowInclusiveFlag;
     }

     private void setSaDoseLowInclusiveFlag(String saDoseLowInclusiveFlag) {
         this.saDoseLowInclusiveFlag = saDoseLowInclusiveFlag;
     }

     private String getSaDoseLowValueTxt() {
         return saDoseLowValueTxt;
     }

     private void setSaDoseLowValueTxt(String saDoseLowValueTxt) {
         this.saDoseLowValueTxt = saDoseLowValueTxt;
     }

     private String getSaDoseLowValueUomCode() {
         return saDoseLowValueUomCode;
     }

     private void setSaDoseLowValueUomCode(String saDoseLowValueUomCode) {
         this.saDoseLowValueUomCode = saDoseLowValueUomCode;
     }

     private String getSaRateHighInclusiveFlag() {
         return saRateHighInclusiveFlag;
     }

     private void setSaRateHighInclusiveFlag(String saRateHighInclusiveFlag) {
         this.saRateHighInclusiveFlag = saRateHighInclusiveFlag;
     }

     private String getSaRateHighValueTxt() {
         return saRateHighValueTxt;
     }

     private void setSaRateHighValueTxt(String saRateHighValueTxt) {
         this.saRateHighValueTxt = saRateHighValueTxt;
     }

     private String getSaRateHighValueUomCode() {
         return saRateHighValueUomCode;
     }

     private void setSaRateHighValueUomCode(String saRateHighValueUomCode) {
         this.saRateHighValueUomCode = saRateHighValueUomCode;
     }

     private String getSaRateIvlValueTxt() {
         return saRateIvlValueTxt;
     }

     private void setSaRateIvlValueTxt(String saRateIvlValueTxt) {
         this.saRateIvlValueTxt = saRateIvlValueTxt;
     }

     private String getSaRateIvlValueUomCode() {
         return saRateIvlValueUomCode;
     }

     private void setSaRateIvlValueUomCode(String saRateIvlValueUomCode) {
         this.saRateIvlValueUomCode = saRateIvlValueUomCode;
     }

     private String getSaRateLowInclusiveFlag() {
         return saRateLowInclusiveFlag;
     }

     private void setSaRateLowInclusiveFlag(String saRateLowInclusiveFlag) {
         this.saRateLowInclusiveFlag = saRateLowInclusiveFlag;
     }

     private String getSaRateLowValueTxt() {
         return saRateLowValueTxt;
     }

     private void setSaRateLowValueTxt(String saRateLowValueTxt) {
         this.saRateLowValueTxt = saRateLowValueTxt;
     }

     private String getSaRateLowValueUomCode() {
         return saRateLowValueUomCode;
     }

     private void setSaRateLowValueUomCode(String saRateLowValueUomCode) {
         this.saRateLowValueUomCode = saRateLowValueUomCode;
     }

     private String getSaRouteCodeEtsId() {
         return saRouteCodeEtsId;
     }

     private void setSaRouteCodeEtsId(String saRouteCodeEtsId) {
         this.saRouteCodeEtsId = saRouteCodeEtsId;
     }

     private String getSaMaxdoseValueTxt()
    {
        return saMaxdoseValueTxt;
    }

     private void setSaMaxdoseValueTxt(String saMaxdoseValueTxt)
    {
        this.saMaxdoseValueTxt = saMaxdoseValueTxt;
    }

     private String getSaMaxdoseValueUomCode()
    {
        return saMaxdoseValueUomCode;
    }

     private void setSaMaxdoseValueUomCode(String saMaxdoseValueUomCode)
    {
        this.saMaxdoseValueUomCode = saMaxdoseValueUomCode;
    }

     private String getSaMaxdaysValueTxt()
    {
        return saMaxdaysValueTxt;
    }

     private void setSaMaxdaysValueTxt(String saMaxdaysValueTxt)
    {
        this.saMaxdaysValueTxt = saMaxdaysValueTxt;
    }

    private String getSaMaxdaysValueUomCode()
    {
        return saMaxdaysValueUomCode;
    }

     private void setSaMaxdaysValueUomCode(String saMaxdaysValueUomCode)
    {
        this.saMaxdaysValueUomCode = saMaxdaysValueUomCode;
    }
     
     
      
}
